package com.errol.sync.controller;

import com.renjia.supervise.config.Response;
import com.renjia.supervise.controller.po.CompanySyncPO;
import com.renjia.supervise.controller.po.DemandSyncPO;
import com.renjia.supervise.controller.po.PayrollSyncPO;
import com.renjia.supervise.controller.po.SettlementSyncPO;
import com.renjia.supervise.service.sync.DataSyncService;
import com.renjia.supervise.service.sync.wrapper.DataSyncWrapperFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zhang xiao bin
 * @version v1.0
 * @date 2021/08/13
 * @since v
 **/
@RestController
@RequestMapping("/data-sync")
@Api(tags = "新版同步接口")
public class DataSyncController {

    private final DataSyncService dataSyncService;
    private final DataSyncService userSyncService;
    private final DataSyncService settlementSyncService;

    public DataSyncController(DataSyncWrapperFactory dataSyncWrapperFactory,
                              @Qualifier("dataSyncService") DataSyncService dataSyncService,
                              @Qualifier("userSyncService") DataSyncService userSyncService,
                              @Qualifier("settlementSyncService") DataSyncService settlementSyncService) {
        this.userSyncService = dataSyncWrapperFactory.getSmartDataSyncWrapper(userSyncService);
        this.dataSyncService = dataSyncWrapperFactory.getSmartDataSyncWrapper(
                dataSyncWrapperFactory.getAsyncDataSyncWrapper(dataSyncService)
        );
        this.settlementSyncService = dataSyncWrapperFactory.getSmartDataSyncWrapper(
                dataSyncWrapperFactory.getAsyncDataSyncWrapper(settlementSyncService)
        );
    }

    @PostMapping("/company")
    @ApiOperation("同步商户信息相关表")
    public Response<?> syncCompany(@Valid CompanySyncPO po) {
        return Response.success(po.triggerSync(userSyncService));
    }

    @PostMapping("/settlement")
    @ApiOperation("手动同步结算材料相关表")
    public Response<?> syncSettlement(@Valid SettlementSyncPO po) {
        return Response.success(po.triggerSync(settlementSyncService));
    }

    @PostMapping("/demand")
    @ApiOperation("手动同步任务接包相关表")
    public Response<?> syncDemandEmployee(@Valid DemandSyncPO po) {
        return Response.success(po.triggerSync(dataSyncService));
    }

    @PostMapping("/payroll")
    @ApiOperation(("手动同步批次发放相关表"))
    public Response<?> syncPayroll(@Valid PayrollSyncPO po) {
        return Response.success(po.triggerSync(dataSyncService));
    }

}
